package com.itheima.health.controller;

import com.itheima.health.common.PageParam;
import com.itheima.health.common.R;
import com.itheima.health.common.ResultPageData;
import com.itheima.health.model.pojos.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;
    /*
    * 分页查询
    * */
    @PostMapping("/findPage")
    public ResultPageData findPage(@RequestBody PageParam pageParam){
        ResultPageData resultPageData = checkGroupService.findPage(pageParam);
        return resultPageData;
    }
    /*
    * 新增检查组
    * */
    @PostMapping("/add")
    public R addCheckGroup(@RequestParam("checkitemIds") ArrayList<Integer> checkitemIds, @RequestBody CheckGroup checkGroup){
        R r = checkGroupService.addCheckGroup(checkitemIds,checkGroup);
        return r;
    }
    /*
    * 检查组编辑-回显基本信息
    * */
    @GetMapping("/findById")
    public R findCheckGroupInfoById(Integer id){
        R r = checkGroupService.findCheckGroupInfoById(id);
        return r;
    }

    /*
    * 更新
    * */
    @PostMapping("/edit")
    public R updateGroupInfo(@RequestParam("checkitemIds") ArrayList<Integer> checkitemIds,@RequestBody CheckGroup checkGroup){
        R r = checkGroupService.updateGroupInfo(checkitemIds,checkGroup);
        return r;
    }

    /*
    * 删除组
    * */
    @GetMapping("/delete")
    public R deleteGroup(Integer id){
        R r = checkGroupService.deleteGroup(id);
        return r;
    }
}
